home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / comm / comm2 / ctsrc701.lha / msgout.c < prev    next >
C/C++ Source or Header  |  1997-01-01  |  21KB  |  906 lines

  1. /*
  2. *                               msgout.c
  3. *
  4. * External Message writer.  For use with external OtherNet parsers.
  5. */
  6. /*
  7. *                               history
  8. *
  9. * 92Jan17 HAW  1.4 - Hard-wire room name to msgs; handle domain field.
  10. * 91Mar26 HAW  1.3 - Virtual rooms.
  11. * 89Sep25 HAW  1.2 - update for Route Mail.
  12. * 88Nov17 HAW  Created.
  13. */
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include "ctdl.h"
  17. #include "2ndfmt.h"
  18. #include "stdarg.h"
  19. #include "dos.h"
  20. #include "math.h"
  21. /*
  22. *                               contents
  23. *
  24. */
  25. #define TITLE           "C86Net Message Exporter "
  26. #define NO_ERROR        0
  27. #define BAD_ARGS        1
  28. #define BAD_TABLE       2
  29. #define NO_NODE         3
  30. #define FATAL           4
  31. #define BAD_OUT_FILE    5
  32. #define LF_ERROR        6
  33.  
  34. char onConsole=1, remoteSysop;
  35.  
  36. FILE            *outfile;
  37. extern FILE *upfd;
  38. extern CONFIG      cfg;                 /* Configuration variables      */
  39. extern MessageBuffer msgBuf;    /* The -sole- message buffer    */
  40. extern aRoom       roomBuf;             /* Room buffer */
  41. extern logBuffer   logBuf;
  42. extern FILE        *roomfl, *logfl;
  43. extern int         thisRoom;    /* Current room    */
  44. extern rTable      *roomTab;
  45. extern struct mBuf mFile1, mFile2;
  46. extern SListBase Serves;
  47. extern NetTable    *netTab;
  48. extern NetBuffer   netBuf, netTemp;
  49. extern FILE        *netfl;
  50. extern LogTable    *logTab;
  51. extern FILE        *msgfl, *msgfl2;
  52. FILE       *GlobalFd, *netMisc;
  53. static int RCount, SCount;
  54. extern int         thisNet;        /* Current node in use          */
  55. char *R_SH_MARK =  "&&";
  56. char *NON_LOC_NET= "%%";
  57. char *LOC_NET =    "++";
  58. char inNet = ANYTIME_NET;
  59. #ifdef ANSI_PROTOTYPING
  60. void NetField(char field, char *value);
  61. void MsgOutGenInit(void);
  62. void MODoVirtuals(void);
  63. void Process(void);
  64. int  FindNet(label nm);
  65. int ThrowAll(int which, char *distance, MSG_NUMBER start, MSG_NUMBER end,
  66. char *room);
  67. void UtilRoomSend(int rover, char *send1, char *send2, char *send3);
  68. void HandleMessage(char *addr1, char *addr2, char *addr3);
  69. int  RoutePath(char *rp, char *str);
  70. char FindMessage(SECTOR_ID loc, MSG_NUMBER id);
  71. void NetFormat(void);
  72. void NowRouteMail(void);
  73. void MoutCC();
  74. void MoutForeign();
  75. int ReadRoutedDest(int c);
  76. int ReadRouted(void);
  77. #endif
  78. void Intel32ToMotorola(UNS_32 *);
  79.  
  80. int  mPrintf(char *format, ...) {return 0; }  /* stub to quiet the linker */
  81.  
  82. /**
  83.   some statistics
  84. **/
  85. int total_msgs = 0;  /* total messages output */
  86.  
  87. /*
  88. * crashout()
  89. *
  90. * Crash exit handler.
  91. */
  92. void crashout(str)
  93. char *str;
  94.   {
  95.   printf(str);
  96.   writeSysTab();
  97.   exit(FATAL);
  98.  
  99.   }
  100. /*
  101. * main()
  102. *
  103. * Main manager
  104. */
  105. int  main(int, char **);
  106. int  main(argc, argv)
  107. char **argv;
  108. int  argc;
  109.   {
  110.   int rover;
  111.   extern char *WRITE_ANY;
  112.   printf("%s %s\n%s\n\n", TITLE, VERSION_NAME, COPYRIGHT);
  113.   /* not enough arguments?  Explain. */
  114.   if (argc < 3)
  115.     {
  116.     printf("usage: MSGOUT nodename file\n");
  117.     exit(BAD_ARGS);
  118.  
  119.     }
  120.   cfg.weAre = UTILITY;
  121.   if (!readSysTab(TRUE, TRUE))
  122.     {
  123.     exit(BAD_TABLE);
  124.  
  125.     }
  126.   if (access(LOCKFILE, 0) != ERROR)
  127.     {
  128.     printf("Please do not run MsgOut using Outside Commands.\n");
  129.     exit(LF_ERROR);
  130.  
  131.     }
  132.   MsgOutGenInit();
  133.   VirtInit();
  134.   if (FindNet(argv[1]) == ERROR)
  135.     {
  136.     writeSysTab();
  137.     printf("Could not find node %s.\n", argv[1]);
  138.     exit(NO_NODE);
  139.  
  140.     }
  141.   if ((outfile = fopen(argv[2], WRITE_ANY)) == NULL)
  142.     {
  143.     writeSysTab();
  144.     printf("Couldn't open output file %s.\n", argv[2]);
  145.     exit(BAD_OUT_FILE);
  146.  
  147.     }
  148.   Process();
  149.   putNet(thisNet, &netBuf);
  150.   writeSysTab();
  151.   printf(" %d total messages output\n");
  152.   return 0;
  153.   }
  154. /*
  155. * MsgOutGenInit()
  156. *
  157. * This handles general initialization.
  158. */
  159. void MsgOutGenInit()
  160.   {
  161.   SYS_FILE fn;
  162.   initNetBuf(&netBuf);
  163.   initNetBuf(&netTemp);
  164.   makeSysName(fn, "ctdlnet.sys", &cfg.netArea);
  165.   openFile(fn, &netfl);
  166.   initRoomBuf(&roomBuf);
  167.   makeSysName(fn, "ctdlroom.sys", &cfg.roomArea);
  168.   openFile(fn, &roomfl);
  169.   InitMsgBase();
  170.  
  171.   }
  172. /*
  173. * Process()
  174. *
  175. * This is the main processor.
  176. */
  177. void Process()
  178.   {
  179.   char          *send1, *send2, *send3;
  180.   label         temp;
  181.   SYS_FILE              fn;
  182.   FILE          *mail;
  183.   int                   rover;
  184.   extern char           *READ_ANY;
  185.   struct netMLstruct    buf;
  186.   /* first we handle Mail>. */
  187.   if (netBuf.nbflags.normal_mail)
  188.     {
  189.     sPrintf(temp, "%d.ml", thisNet);
  190.     makeSysName(fn, temp, &cfg.netArea);
  191.     if ((mail = fopen(fn, READ_ANY)) == NULL)
  192.       {
  193.       printf("WARNING: Couldn't open %s for mail delivery to %s.\n",
  194.       fn, netBuf.netName);
  195.  
  196.       }
  197.     else
  198.       {
  199.       while (getMLNet(mail, buf))
  200.       if (FindMessage(buf.ML_loc, buf.ML_id))
  201.         {
  202.         strCpy(msgBuf.mbroom, "Mail");
  203.         NetFormat();
  204.  
  205.         }
  206.       fclose(mail);
  207.       unlink(fn);               /* kill mail file */
  208.  
  209.       }
  210.     netBuf.nbflags.normal_mail = FALSE;
  211.  
  212.     }
  213.   NowRouteMail();               /* now handle any route mail */
  214.   /* now we handle the shared rooms */
  215.   for (rover = 0; rover < SHARED_ROOMS; rover++)
  216.     {
  217.     /* if we share this room, check for new msgs. */
  218.     if (isSharedRoom(thisNet, rover) && roomValidate(thisNet, rover))
  219.       {
  220.       getRoom(netRoomSlot(rover));
  221.       send1 = R_SH_MARK;
  222.       send2 = send3 = "guh";
  223.       switch (roomBuf.rbShareType)
  224.         {
  225.         case REG_HOST:
  226.         printf("WARNING: Please do not use Regional Host settings.\n");
  227.         printf("\nThey are obsolete.\n");
  228.         case PEON:
  229.         break;
  230.         case BACKBONE:
  231.         switch (netBuf.netRooms[rover].mode)
  232.           {
  233.           case PEON:
  234.           send2  = NON_LOC_NET;
  235.           break;
  236.           case ACTIVE_BACKBONE:
  237.           case PASS_BACKBONE:
  238.           case REG_HOST:
  239.           send2 = NON_LOC_NET;
  240.           send3 = LOC_NET;
  241.           break;
  242.           default: crashout("shared rooms: #2");
  243.  
  244.           }
  245.         break;
  246.         default: crashout("shared rooms: #1");
  247.  
  248.         }
  249.       UtilRoomSend(rover, send1, send2, send3);
  250.  
  251.       }
  252.  
  253.     }
  254.   MODoVirtuals();
  255.   UpdVirtStuff();
  256.  
  257.   }
  258. /*
  259. * UtilRoomSend()
  260. *
  261. * Send stuff out.
  262. */
  263. void UtilRoomSend(rover, send1, send2, send3)
  264. int rover;
  265. char *send1, *send2, *send3;
  266.   {
  267.   int i;
  268.   for (i = 0; i < MSGSPERRM; i++)
  269.     {
  270.     if (roomBuf.msg[i].rbmsgNo > netBuf.netRooms[rover].lastMess)
  271.       {
  272.       if (FindMessage(roomBuf.msg[i].rbmsgLoc, roomBuf.msg[i].rbmsgNo))
  273.         {
  274.         strcpy(msgBuf.mbroom, roomBuf.rbname);
  275.         HandleMessage(send1, send2, send3);
  276.  
  277.         }
  278.  
  279.       }
  280.  
  281.     }
  282.   netBuf.netRooms[rover].lastMess = roomTab[thisRoom].rtlastMessage;
  283.   netTab[thisNet].netTRooms[rover].lastMess =
  284.   roomTab[thisRoom].rtlastMessage;
  285.  
  286.   }
  287. /*
  288. * HandleMessage()
  289. *
  290. * This decides if a message should be sent out.
  291. */
  292. void HandleMessage(addr1, addr2, addr3)
  293. char *addr1, *addr2, *addr3;
  294.   {
  295.   if ((strncmp(msgBuf.mbaddr, addr1, strLen(addr1)) == SAMESTRING  ||
  296.   strncmp(msgBuf.mbaddr, addr2, strLen(addr2))      == SAMESTRING  ||
  297.   strncmp(msgBuf.mbaddr, addr3, strLen(addr3))      == SAMESTRING) &&
  298.   RoutePath(LOC_NET, msgBuf.mbaddr)     != thisNet &&
  299.   RoutePath(NON_LOC_NET, msgBuf.mbaddr) != thisNet)
  300.     {
  301.     NetFormat();
  302.  
  303.     }
  304.  
  305.   }
  306. /*
  307. * RoutePath()
  308. *
  309. * This function returns the number of the node that routed this msg
  310. * to here.  If the msg was not routed in from a BackBone, then
  311. * return ERROR, which will never match another node's #.
  312. * 88Oct13: Now simply check for msg origin, assume if one exists
  313. * that it should be checked.  Don't remember why it is restricted
  314. * to only BACKBONE-routed msgs.  Doesn't seem necessary.
  315. */
  316. int RoutePath(rp, str)
  317. char *str, *rp;
  318.   {
  319.   if (strncmp(rp, str, strLen(rp)) == SAMESTRING)
  320.     {
  321.     if (strLen(str) != strLen(rp)) /* prevent return of 0 */
  322.     return atoi(str + 2);
  323.  
  324.     }
  325.   return ERROR;
  326.  
  327.   }
  328. /*
  329. * FindNet()
  330. *
  331. * This function will find the named node.  Stolen from searchNameNet/NETMISC.
  332. */
  333. int  FindNet(nm)
  334. label nm;
  335.   {
  336.   int rover;
  337.   for (rover = 0; rover < cfg.netSize; rover++)
  338.     {
  339.     if (netTab[rover].ntflags.in_use &&
  340.     hash(nm) == netTab[rover].ntnmhash)
  341.       {
  342.       getNet(rover, &netBuf);
  343.       if (strCmpU(netBuf.netName, nm) == SAMESTRING)
  344.       return rover;
  345.  
  346.       }
  347.  
  348.     }
  349.   return ERROR;
  350.  
  351.   }
  352. /*********** These functions stolen & modified from MSG.C ***************/
  353. /*
  354. * FindMessage()
  355. *
  356. * This gets all set up to do something with a message.  We use this rather
  357. * than the findMessage in libmsg.c so we can automatically read in the 'M'
  358. * field.
  359. */
  360. char FindMessage(loc, id)
  361. SECTOR_ID  loc;         /* sector in message.buf */
  362. MSG_NUMBER id;          /* unique-for-some-time ID# */
  363.   {
  364.   MSG_NUMBER here;
  365.   startAt(msgfl, &mFile1, loc, 0);
  366.   do
  367.     {
  368.     getMessage(getMsgChar, FALSE, TRUE, TRUE);
  369.     here = atol(msgBuf.mbId);
  370.  
  371.     }
  372.   while (here != id &&  mFile1.thisSector == loc);
  373.   return (char) ((here == id));
  374.  
  375.   }
  376. /*
  377. * NetFormat()
  378. *
  379. * This function writes a message to disk.
  380. */
  381. void NetFormat()
  382.   {
  383.   MSG_NUMBER val;
  384.   if (!msgBuf.mborig[0])
  385.   strCpy(msgBuf.mborig, cfg.nodeId + cfg.codeBuf);
  386.   if (!msgBuf.mboname[0])
  387.   strCpy(msgBuf.mboname, cfg.nodeName + cfg.codeBuf);
  388.   if (!msgBuf.mbsrcId[0])
  389.     {
  390.     val = atol(msgBuf.mbId);
  391.     sPrintf(msgBuf.mbsrcId, "%ld %ld",
  392.     (val & 0xffff0000) >> 16, val & 0xffffl);
  393.  
  394.     }
  395.   if (msgBuf.mbauth[0])   NetField('A', msgBuf.mbauth);
  396.   if (msgBuf.mbdate[0])   NetField('D', msgBuf.mbdate);
  397.   if (msgBuf.mbtime[0])   NetField('C', msgBuf.mbtime);
  398.   if (msgBuf.mboname[0])  NetField('N', msgBuf.mboname);
  399.   if (msgBuf.mbdomain[0]) NetField('X', msgBuf.mbdomain);
  400.   if (msgBuf.mborig[0])   NetField('O', msgBuf.mborig);
  401.   if (msgBuf.mbroom[0])   NetField('R', msgBuf.mbroom);
  402.   if (msgBuf.mbsrcId[0])  NetField('S', msgBuf.mbsrcId);
  403.   if (msgBuf.mbto[0])     NetField('T', msgBuf.mbto);
  404.   if (msgBuf.mbOther[0])  NetField('P', msgBuf.mbOther);
  405.   RunList(&msgBuf.mbCC, MoutCC);
  406.   RunList(&msgBuf.mbForeign, MoutForeign);
  407.   NetField('M', msgBuf.mbtext);
  408.   total_msgs++;
  409.   }
  410. /*
  411. * NetField()
  412. *
  413. * Work function to write out a field and its identifier.
  414. */
  415. void NetField(field, value)
  416. char *value, field;
  417.   {
  418.   fprintf(outfile, "%c%s", field, value);
  419.   putc(0, outfile);
  420.  
  421.   }
  422. /*
  423. * MoutCC()
  424. *
  425. * This handles the CC field of a message.
  426. */
  427. void MoutCC(dd)
  428. char *dd;
  429.   {
  430.   NetField('W', dd);
  431.  
  432.   }
  433. /*
  434. * MoutForeign()
  435. *
  436. * This handles the Foreign fields of a message.
  437. */
  438. void MoutForeign(dd)
  439. char *dd;
  440.   {
  441.   NetField(dd[0], dd + 1);
  442.  
  443.   }
  444. static int  RWorkBuf[7];
  445. /*
  446. * NowRouteMail()
  447. *
  448. * This function handles outgoing route mail.
  449. */
  450. void NowRouteMail()
  451.   {
  452.   int           rover;
  453.   label temp;
  454.   SYS_FILE      fn;
  455.   extern char *READ_ANY, OverRides;
  456.   if (!netBuf.nbflags.HasRouted)
  457.   return;
  458.   for (rover = 0; rover <= netBuf.nbHiRouteInd; rover++)
  459.     {
  460.     sPrintf(temp, "R%d.%d", thisNet, rover);
  461.     makeSysName(fn, temp, &cfg.netArea);
  462.     if ((netMisc = safeopen(fn, READ_ANY)) != NULL)
  463.       {
  464.       getMsgStr(getNetChar, temp, NAMESIZE);
  465.       getMsgStr(getNetChar, temp, NAMESIZE);
  466.       StartDecode(ReadRoutedDest);
  467.       RCount = SCount = 0;
  468.       while (getMessage(ReadRouted, TRUE, TRUE, TRUE))
  469.         {
  470.         strCpy(msgBuf.mbroom, "Mail");
  471.         NetFormat();
  472.  
  473.         }
  474.       fclose(netMisc);
  475.       unlink(fn);
  476.  
  477.       }
  478.  
  479.     }
  480.   netBuf.nbflags.HasRouted = FALSE;
  481.   netBuf.nbHiRouteInd        = 0;
  482.  
  483.   }
  484. /*
  485. * ReadRoutedDest()
  486. *
  487. * A work function to read encrypted data.
  488. */
  489. int ReadRoutedDest(int c)
  490.   {
  491.   RWorkBuf[RCount++] = c;
  492.   return TRUE;
  493.  
  494.   }
  495. /*
  496. * ReadRouted()
  497. *
  498. * This function will read a routed char for getMessage().
  499. */
  500. int ReadRouted()
  501.   {
  502.   int c;
  503.   if (RCount != SCount)
  504.   return RWorkBuf[SCount++];
  505.   RCount = SCount = 0;
  506.   while (SCount == RCount && (c = fgetc(netMisc)) != EOF)
  507.   Decode(c);
  508.   if (RCount != SCount)
  509.   return RWorkBuf[SCount++];
  510.   if (c == EOF) StopDecode();
  511.   if (RCount != SCount)
  512.   return RWorkBuf[SCount++];
  513.   return -1;
  514.  
  515.   }
  516. /*
  517. * getNetChar()
  518. *
  519. * This function gets a character from a network temporary file.
  520. */
  521. int getNetChar()
  522.   {
  523.   int c;
  524.   c = fgetc(netMisc);
  525.   if (c == EOF) return -1;
  526.   return c;
  527.  
  528.   }
  529. #define WeServe(x)      SearchList(&Serves, x)
  530. /*
  531. * LocalName()
  532. *
  533. * This takes a string of form <system> _ <domain> and attempts to discover if
  534. * this domain mapped system is actually a local.  This is used when we're
  535. * sending mail and are trying to find out if a Who Else override needs to be
  536. * generated.  Ugly kludge, but, hey, that's what programming's all about, eh?
  537. */
  538. char *LocalName(char *system)
  539.   {
  540.   char *domain, *System;
  541.   if ((domain = strchr(system, '_')) == NULL) return system;
  542.   domain += 2;  /* always preceded by a space -- or so we assume */
  543.   if (strCmpU(domain, cfg.codeBuf + cfg.nodeDomain) == SAMESTRING ||
  544.   WeServe(domain) != NULL)
  545.     {
  546.     System = strdup(system);
  547.     if ((domain = strchr(System, ' ')) == NULL)
  548.     return system;      /* should never happen, though */
  549.     *domain = NULL;
  550.     if (searchNameNet(System, &netTemp) != ERROR)
  551.       {
  552.       free(System);
  553.       return netTemp.netName;
  554.  
  555.       }
  556.     free(System);
  557.  
  558.     }
  559.   return system;
  560.  
  561.   }
  562. /*
  563. * SepNameSystem()
  564. *
  565. * This will parse an Other Recipient spec.
  566. */
  567. char SepNameSystem(char *string, char *person, char *system, NetBuffer *buf)
  568.   {
  569.   char  *c;
  570.   label domain;
  571.   char dup, work[150];          /* should be sufficient */
  572.   int   slot;
  573.   strCpy(work, string);
  574.   if ((c = strchr(work, '@')) == NULL)
  575.     {
  576.     if (strLen(work) >= NAMESIZE) return BAD_FORMAT;
  577.     strCpy(person, string);
  578.     return NOT_SYSTEM;
  579.  
  580.     }
  581.   *c++ = 0;
  582.   NormStr(work);
  583.   NormStr(c);
  584.   if (strLen(c) >= NAMESIZE * 2 || strLen(work) >= NAMESIZE)
  585.   return BAD_FORMAT;
  586.   strCpy(system, c);
  587.   strCpy(person, work);
  588.   if (buf == NULL) return IS_SYSTEM;    /* very minor cheat - see CTDL.C */
  589.   if ((slot = searchNameNet(c, buf)) != ERROR)
  590.     {
  591.     /* try secondary lists */
  592.     strCpy(system, buf->netName);       /* get "real" name */
  593.     if (buf->nbflags.local)
  594.       {
  595.       return IS_SYSTEM;
  596.  
  597.       }
  598.  
  599.     }
  600.   if (SystemInSecondary(c, domain, &dup))
  601.     {
  602.     if (dup)
  603.       {
  604.       /* oops */
  605.       return (char) (slot == ERROR) ? NO_SYSTEM : IS_SYSTEM;
  606.  
  607.       }
  608.     if (strCmpU(domain, cfg.nodeDomain + cfg.codeBuf) == SAMESTRING &&
  609.     (strCmpU(c, cfg.nodeName + cfg.codeBuf) == SAMESTRING ||
  610.     strCmpU(c, UseNetAlias(cfg.nodeName+cfg.codeBuf, TRUE))
  611.     == SAMESTRING))
  612.       {
  613.       printf("Hey, that's this system!\n ");
  614.       return SYSTEM_IS_US;
  615.  
  616.       }
  617.     sPrintf(system, "%s _ %s", c, domain);
  618.     return IS_SYSTEM;
  619.  
  620.     }
  621.   return (char) (slot == ERROR) ? NO_SYSTEM : IS_SYSTEM;
  622.  
  623.   }
  624. static label SearchResult;
  625. static char  *SearchTarget, GetAlias;
  626. /*
  627. * UseNetAlias()
  628. *
  629. * This will find a usenet alias or the converse.
  630. */
  631. char *UseNetAlias(char *Name, char FindAlias)
  632.   {
  633.   void *EatTrans();
  634.   SListBase Dummy =
  635.     {
  636.     NULL, NULL, NULL, NULL, EatTrans
  637.  
  638.     };
  639.   SYS_FILE fn;
  640.   char *c, *WorkName;
  641.   WorkName = strdup(Name);      /* use a work buffer */
  642.   SearchResult[0] = 0;
  643.   SearchTarget = WorkName;
  644.   if (!FindAlias) while ((c = strchr(WorkName, ' ')) != NULL) *c = '_';
  645.   makeSysName(fn, "aliases.sys", &cfg.roomArea);
  646.   GetAlias = FindAlias;
  647.   MakeList(&Dummy, fn, NULL);   /* CHEAT!  WHEEEEEE! */
  648.   free(WorkName);
  649.   if (strLen(SearchResult) == 0) return Name;
  650.   if (FindAlias) while ((c = strchr(SearchResult, '_')) != NULL) *c = ' ';
  651.   return SearchResult;
  652.  
  653.   }
  654. /*
  655. * EatTrans()
  656. *
  657. * This will eat a line of input for alias processing.
  658. */
  659. void *EatTrans(char *line)
  660.   {
  661.   char *c;
  662.   if ((c = strchr(line, ' ')) != NULL)
  663.     {
  664.     *c = 0;
  665.     if (GetAlias)
  666.       {
  667.       /* check second field */
  668.       if (strCmpU(c + 1, SearchTarget) == SAMESTRING)
  669.         {
  670.         strCpy(SearchResult, line);
  671.  
  672.         }
  673.  
  674.       }
  675.     else
  676.       {
  677.       /* check first field */
  678.       if (strCmpU(line, SearchTarget) == SAMESTRING)
  679.         {
  680.         strCpy(SearchResult, c + 1);
  681.  
  682.         }
  683.  
  684.       }
  685.  
  686.     }
  687.   return NULL;
  688.  
  689.   }
  690. /*
  691. * SearchSecondary()
  692. *
  693. * This searches a secondary (domain) list for a system.
  694. */
  695. static char SearchSecondary(char *secondary,char *Name,char *Domain,char *isdup)
  696.   {
  697.   FILE *fd;
  698.   int  bucket;
  699.   char found, *tab, *c, *tab2;
  700.   char line[90];
  701.   JumpInfo JumpTable[BUCKETCOUNT];
  702.   if ((fd = fopen(secondary, READ_ANY)) == NULL)
  703.   return FALSE;
  704.   fread(line, VERS_SIZE + 1, 1, fd);
  705.   fread(JumpTable, sizeof JumpTable, 1, fd);
  706.   #ifdef IS_MOTOROLA
  707.   for (bucket = 0; bucket < BUCKETCOUNT; bucket++)
  708.   Intel32ToMotorola(&JumpTable[bucket].offset);
  709.   #endif
  710.   bucket = (isdigit(Name[0])) ? Name[0] - '0' :
  711.   toUpper(Name[0]) - 'A' + 10;
  712.   fseek(fd, JumpTable[bucket].offset, 0);
  713.   found = FALSE;
  714.   do
  715.     {
  716.     *isdup = FALSE;
  717.     if (fgets(line, sizeof line, fd) == NULL) break;
  718.     if ((tab2 = strchr(line, '\n')) != NULL)
  719.     *tab2 = 0;
  720.     if (strlen(line) == 0)
  721.       {
  722.       break;
  723.  
  724.       }
  725.     if (line[0] <= ' ')
  726.       {
  727.       switch (line[0])
  728.         {
  729.         case DUP:
  730.         *isdup = TRUE;
  731.         break;
  732.         default: printf("Ooop!");
  733.         break;
  734.  
  735.         }
  736.       c = line + 1;
  737.  
  738.       }
  739.     else c = line;
  740.     tab = strchr(c, '\t');
  741.     *tab++ = 0;
  742.     if (strCmpU(c, Name) == 0)
  743.     found = TRUE;
  744.     if (strCmpU(c, Name) > 0) break;
  745.  
  746.     }
  747.   while (!found);
  748.   if (found)
  749.     {
  750.     if ((tab2 = strchr(tab, '\t')) != NULL)
  751.     *tab2++ = 0;
  752.     strCpy(Domain, tab);
  753.     if (tab2 != NULL)    /* alias?  Copy it into search string */
  754.     strCpy(Name, tab2);
  755.  
  756.     }
  757.   fclose(fd);
  758.   return found;
  759.  
  760.   }
  761. /*
  762. * SystemInSecondary()
  763. *
  764. * This will look for a system in secondary lists.
  765. */
  766. char SystemInSecondary(char *Name, char *Domain, char *dup)
  767.   {
  768.   int rover;
  769.   char *sep;
  770.   SYS_FILE secondary;
  771.   label name;
  772.   char WorkName[(NAMESIZE * 2) + 1];
  773.   char SearchSecondary(char *secondary,char *Name,char *Domain,char *isdup);
  774.   strCpy(WorkName, Name);
  775.   /* is the domain specified already?  if so, parse it */
  776.   if ((sep = strchr(WorkName, '_')) != NULL ||
  777.   (sep = strchr(WorkName, '.')) != NULL)
  778.     {
  779.     *sep++ = 0;
  780.     NormStr(WorkName);
  781.     NormStr(sep);
  782.     if (strchr(sep, '_') != NULL ||
  783.     strchr(sep, '.') != NULL)
  784.     return FALSE;       /* no subdomains */
  785.     strCpy(Name, WorkName);
  786.     strCpy(Domain, sep);
  787.     *dup = FALSE;               /* by definition */
  788.     return TRUE;
  789.  
  790.     }
  791.   Domain[0] = 0;
  792.   for (rover = 0; rover < 100; rover++)
  793.     {
  794.     sPrintf(name, "nodes%d.fst", rover);
  795.     makeSysName(secondary, name, &cfg.netArea);
  796.     if (access(secondary, 0) != 0) break;
  797.     if (SearchSecondary(secondary, Name, Domain, dup)) break;
  798.  
  799.     }
  800.   strCpy(WorkName, Name);
  801.   /* make sure we found something and it's not us */
  802.   return (Domain[0] != 0 &&
  803.   strCmpU(Name, cfg.codeBuf + cfg.nodeName) != SAMESTRING &&
  804.   strCmpU(UseNetAlias(WorkName,FALSE), cfg.codeBuf + cfg.nodeName)
  805.   != SAMESTRING);
  806.  
  807.   }
  808. extern VirtualRoom *VRoomTab;
  809. extern VirtNet     *VirtNetList;
  810. extern char VirtualInUse;
  811. extern int  VirtSize, VNetSize;
  812. /*
  813. * MODoVirtuals()
  814. *
  815. * This sends rooms to another system, if needed.
  816. */
  817. void MODoVirtuals()
  818.   {
  819.   int rover, which, x;
  820.   if (!VirtualInUse) return ;
  821.   for (rover = 0; rover < VIRT_LIMIT; rover++)
  822.     {
  823.     x = VirtNetList[thisNet].VirtList[rover].WhichVirt;
  824.     if (x >= VirtSize || x < 0 || !VRoomInuse(x))
  825.     VirtNetList[thisNet].VirtList[rover].WhichVirt = -1;
  826.     if (VirtNetList[thisNet].VirtList[rover].WhichVirt != -1)
  827.       {
  828.       SendVirtual(rover, NULL, NULL, NULL);
  829.  
  830.       }
  831.  
  832.     }
  833.  
  834.   }
  835. /*
  836. * SendVirtual()
  837. *
  838. * This manages sending a room to another system.
  839. */
  840. int SendVirtual(int VirtIndex, char *d1, char *d2, char *d3)
  841.   {
  842.   int   VirtNo, count;
  843.   MSG_NUMBER StartMsg;
  844.   VirtNo = VirtNetList[thisNet].VirtList[VirtIndex].WhichVirt;
  845.   /* Send all the new LD messages received */
  846.   StartMsg = VirtNetList[thisNet].VirtList[VirtIndex].LDSent;
  847.   count = ThrowAll(VirtNo, LD_DIR, StartMsg, VRoomTab[VirtNo].vrHiLD,
  848.   VRoomTab[VirtNo].vrName);
  849.   VirtNetList[thisNet].VirtList[VirtIndex].LDSent =
  850.   VRoomTab[VirtNo].vrHiLD;
  851.   if (VirtNetList[thisNet].VirtList[VirtIndex].mode != PEON)
  852.     {
  853.     StartMsg = VirtNetList[thisNet].VirtList[VirtIndex].LocSent;
  854.     count += ThrowAll(VirtNo, LOCAL_DIR, StartMsg,
  855.     VRoomTab[VirtNo].vrHiLocal, VRoomTab[VirtNo].vrName);
  856.     VirtNetList[thisNet].VirtList[VirtIndex].LocSent =
  857.     VRoomTab[VirtNo].vrHiLocal;
  858.  
  859.     }
  860.   VRoomTab[VirtNo].vrChanged |= SENT_DATA;
  861.   return count;
  862.  
  863.   }
  864. /*
  865. * ThrowAll()
  866. *
  867. * This sends a virtual room to another system.
  868. */
  869. static int ThrowAll(int which, char *distance, MSG_NUMBER start, MSG_NUMBER end,
  870. char *room)
  871.   {
  872.   MSG_NUMBER  rover;
  873.   int           count=0;
  874.   char  fn[100];
  875.   extern char *READ_ANY;
  876.   extern PROTO_TABLE Table[];
  877.   extern int    TransProtocol;
  878.   for (rover = start + 1; rover <= end; rover++)
  879.     {
  880.     CreateVAName(fn, which, distance, rover);
  881.     if ((netMisc = safeopen(fn, READ_ANY)) != NULL)
  882.       {
  883.       while (getMessage(getNetChar, TRUE, TRUE, TRUE))
  884.         {
  885.         count++;
  886.         strCpy(msgBuf.mbroom, room);
  887.         NetFormat();
  888.  
  889.         }
  890.       fclose(netMisc);
  891.  
  892.       }
  893.  
  894.     }
  895.   return count;
  896.  
  897.   }
  898. void Intel32ToMotorola(UNS_32 *val)
  899.   {
  900.   unsigned long temp;
  901.   temp = *val;
  902.   *val = ((ULONG)(temp & 0xff) << 24) + ((ULONG)(temp & 0xff00) << 8) +
  903.   ((ULONG)(temp & 0xff0000) >> 8) + ((ULONG)(temp &0xff000000) >> 24);
  904.  
  905.   }
  906.